#!/bin/bash
# 修改bashrc实现start启动archtoolin
cat >> ~/.bashrc << EOF
alias start="sh ~/.archtoolin.sh"
EOF
# 写入安装脚本
cat >> ~/.archtoolin.sh << EOF
#!/bin/bash
# Whiptail实现图形化菜单
SELECTION=$(whiptail --title "Archtoolin" --menu "Please select." 15 60 4 \
"1" "Check Internet" \
"2" "Disk Partition" \
"3" "Source Choose" \
"4" "Install" \
"5" "About" \ 3>&1 1>&2 2>&3)
# 判断用户是否选择了取消
exitstatus=$?
if [ $exitstatus != 0 ]; then
    echo "You chose Cancel."
    exit $exitstatus
fi
# case in 实现菜单选择
case "$SELECTION" in
    1)
        # 用ping检测网络连接
        ping -c 3 www.baidu.com
        ;;
    2)
        # 远程执行磁盘分区脚本
        sh -c "$(curl -fsSL https://gitee.com/bilibili-linux-sen/archtoolin/raw/master/diskpart.sh)"
        ;;
    3)
        # 远程执行镜像选择脚本
        sh -c "$(curl -fsSL https://gitee.com/bilibili-linux-sen/archtoolin/raw/master/mirrorselect.sh)"
        ;;
    4)
        # 远程执行系统安装脚本
        sh -c "$(curl -fsSL https://gitee.com/bilibili-linux-sen/archtoolin/raw/master/archinstaller.sh)"
        ;;
    5)
        # 查看软件信息
        sh -c "$(curl -fsSL https://gitee.com/bilibili-linux-sen/archtoolin/raw/master/about.sh)"
esac
# 提示用户连接失败
if [ $? -ne 0 ]l then
    echo -e "\033[0;31mError: \e[0m load failed, please check your Internet. "
    exit $?
fi
EOF